const dayjs = require("dayjs")
function formatDateWithDayjs(
  date = new Date(),
  format = "YYYY-MM-DD HH:mm:ss"
) {
  const d = dayjs(date)
  if (!d.isValid()) {
    throw new Error("Invalid date")
  }
  return d.format(format)
}

// 使用示例
console.log(formatDateWithDayjs()) // 当前时间
console.log(formatDateWithDayjs("2023-05-20", "YYYY/MM/DD"))
console.log(formatDateWithDayjs(1684567890000, "YYYY年MM月DD日 HH时mm分"))